package com.alex.renju.renju.controller;

import com.alex.renju.renju.service.WebSocketServer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Author: Alex
 * @Description:
 * @Date: 2021/9/25
 */
@Controller
public class RenjuController {

    @RequestMapping("/")
    public String renju() {
        return "renju";
    }


    @RequestMapping("/play/{to}/{me}/{type}")
    public String play(@PathVariable("to") String to, @PathVariable("me") String me, @PathVariable("type") String type, ModelMap mmap) throws IOException {
        if ("1".equals(type)) {
            //给创建房间者发消息说我进房间了准备开始吧
            WebSocketServer.sendInfo("{\"toUser\":\"" + me + "\",\"status\":\"0\",\"x\":\"0\",\"y\":\"0\"}", to);
        }
        mmap.put("to", to);
        mmap.put("me", me);
        mmap.put("type", type);
        return "play";
    }

}
